package com.example.jpa.demo_jpa.service.impl;

import com.example.jpa.demo_jpa.dao.PhoneTypeDao;
import com.example.jpa.demo_jpa.model.PhoneType;
import com.example.jpa.demo_jpa.repository.PhoneTypeRepository;
import com.example.jpa.demo_jpa.service.PhoneTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PhoneTypeServiceImpl implements PhoneTypeService {
   @Resource
   private PhoneTypeRepository phoneTypeRepository;
   @Autowired
   private PhoneTypeDao phoneTypeDao;

    @Override
    public PhoneType findById(String id) {
        return phoneTypeRepository.findById(id).orElse(null);
    }

    @Override
    public List<PhoneType> findAll() {
        return phoneTypeRepository.findAll();
    }

    @Override
    public PhoneType save(PhoneType phoneType) {
        return phoneTypeRepository.save(phoneType);
    }


    @Override
    public void delete(String id) {
         phoneTypeRepository.deleteById(id);
    }

    @Override
    public PhoneType findByNumber(String number) {
        return phoneTypeDao.findByNumber(number);
    }

}
